/**
    店铺审核 组件
**/
(function (vc) {

    vc.extends({
        data: {
            shopAuditDetailInfo: {
                auditId: '',
                shopId: '',
                shopLogo: '',
                storeId: '',
                shopName: '',
                shopDesc: '',
                mapX: '',
                mapY: '',
                sendAddress: '',
                returnAddress: '',
                shopTypeName: '',
                areaName: '',
                returnPerson: '',
                returnLink: '',
                state: '',
                shopType: '',
                openType: '',
                areaCode: '',
                auditOpinion: '',
                applyOpinion: '',
                statusCd: '',
            },
            auditInfo: {
                state: '',
                auditOpinion: ''
            }
        },
        _initMethod: function () {
            //根据请求参数查询 查询 业主信息
            $that.shopAuditDetailInfo.auditId = vc.getParam('auditId');
            $that.shopAuditDetailInfo.shopId = vc.getParam('shopId');
            $that._loadShopAuditInfoData();
        },
        _initEvent: function () {
            vc.on('shopAuditDetail', 'chooseShopAudit', function (_app) {
                vc.copyObject(_app, $that.shopAuditDetailInfo);
                $that._needShopInfo($that.shopAuditDetailInfo.shopId);
            });
            vc.on('shopAuditDetail', 'onIndex', function (_index) {
                $that.shopAuditDetailInfo.index = _index;
            });

        },
        methods: {
            auditValidate() {
                return vc.validate.validate({
                    auditInfo: $that.auditInfo
                }, {
                    'auditInfo.state': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "审核状态不能为空"
                        },
                        {
                            limit: "num",
                            param: "",
                            errInfo: "审核状态错误"
                        },
                    ],
                    'auditInfo.auditOpinion': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "原因内容不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "200",
                            errInfo: "原因内容不能超过200"
                        },
                    ]
                });
            },
            _auditSubmit: function () {
                if (!$that.auditValidate()) {
                    vc.toast(vc.validate.errInfo);
                    return;
                }
                let _auditInfo = {
                    state: $that.auditInfo.state,
                    auditOpinion: $that.auditInfo.auditOpinion
                };
                if (_auditInfo.state == '1200') {
                    _auditInfo.auditOpinion = '拒绝:' + _auditInfo.auditOpinion;
                }
                _auditInfo.shopId = $that.shopAuditDetailInfo.shopId;
                _auditInfo.storeId = $that.shopAuditDetailInfo.storeId;
                _auditInfo.auditId = $that.shopAuditDetailInfo.auditId;
                _auditInfo.remark = _auditInfo.auditOpinion;
                vc.http.apiPost('/shop.auditEditShop',
                    JSON.stringify(_auditInfo),
                    {
                        emulateJSON: true
                    },
                    function (json, res) {
                        let _json = JSON.parse(json)
                        if (_json.code != 0) {
                            vc.toast(_json.msg);
                            return;
                        }
                        vc.toast("处理成功");
                        vc.goBack();
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                        vc.toast("处理失败：" + errInfo);
                    }
                );
                return;
            },
            _openTypeName: function (_state) {
                if (_state == "1") {
                    return "商家"
                }
                if (_state == "2") {
                    return "服务"
                }
                if (_state == "3") {
                    return "商家和服务"
                }
            },
            _loadShopAuditInfoData: function () {
                let param = {
                    params: {
                        page:1,
                        row:1,
                        auditId:$that.shopAuditDetailInfo.auditId,
                    }
                };
                //发送get请求
                vc.http.apiGet('/shopAudit.queryShopAudit',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        vc.copyObject(_json.data[0],$that.shopAuditDetailInfo);
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            }
        }
    });

})(window.vc);
